<?php

namespace app\api\model\event;
use app\api\model\BaseModel;
use LinCmsTp5\admin\model\LinUser;

class Order extends BaseModel
{
    protected $table = 'order';
    protected $deleteTime = 'delete_time';
    protected $autoWriteTimestamp = 'datetime';


    public function product(){
        return $this->hasOne(Product::class,'id','product_id')->field('id,title,url');
    }

    public function mName(){
        return $this->hasOne(Merchant::class,'id','merchant_id')->bind(['merchant_name'=>'company']);
    }

    public function aName(){
        return $this->hasOne(LinUser::class,'id','author_id')->bind(['author_name'=>'username']);
    }

    public function tNum(){
        return $this->hasMany(Event::class,'order_id','id')->where("type",1)
            ->where("status",3)
            ->field("order_id");
    }

    public function vNum(){
        return $this->hasMany(Event::class,'order_id','id')->where("type",2)
            ->where("status",3)
            ->field("order_id");
    }


}
